package perf.data;

public class Binary extends BaseItem<Sourcefile,Run> {

	public Binary( String path ) {
		super( path );
	}
	
	@Override
	public long getCost(int costidx ) {
		long costs = 0;
		for ( Sourcefile s : siblings() ) {
			costs += s.getCost(costidx);
		}
		
		return costs;
	}
	
	public boolean hasSource( String sourcefile ) {
		return hasSibling( sourcefile );
	}
	
	public Sourcefile getSource( String file ) {
		return super.getSibling( file );
	}
	
	public Sourcefile getSourceInstance( String name ) {
		Sourcefile f = findSibling( name );
		
		if ( f != null ) {
			return f;
		} else {
			return add( new Sourcefile( name ) );
		}
	}
	
	@Override
	public String toString( ) {
		StringBuffer sb = new StringBuffer();
		
		sb.append( "\tBinary: \"" + getName() + "\"\n" );
		
		if ( siblings() != null ) { 	
			for (Sourcefile s: siblings() ) {
				sb.append( s.toString() );
			}
		} else {
			sb.append( "No sourcefiles defined\n" );
		}
		return sb.toString();
	}
}
